package com.itheima.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.itheima.dao.MemberDao;
import com.itheima.dao.OrderDao;
import com.itheima.entity.Result;
import com.itheima.pojo.Member;
import com.itheima.pojo.Setmeal;
import com.itheima.service.CheckcordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service(interfaceClass = CheckcordService.class)
@Transactional
public class CheckcordServiceImpl implements CheckcordService {
    @Autowired
    private MemberDao memberDao;

    @Autowired
    private OrderDao orderDao;

    @Override
    public Result findCheckrecordByTelephone(String telephone) {
        Member member = memberDao.findByTelephone(telephone);
        System.out.println(member);
        // 预约人名字
        String name = member.getName();
        // 预约人性别
        String sex = member.getSex();

        Integer memberId = member.getId();
        Setmeal setmeal = orderDao.findSetmealByMemberId(memberId);
        if (setmeal == null){
            return new Result(false,"您还没有体检过");
        }
        // 预约人套餐
        String setmealName = setmeal.getName();
        Map<String,Object> map = new HashMap();
        map.put("name",name);
        map.put("sex",sex);
        map.put("setmealName",setmealName);

        ArrayList<Map<String,Object>> checkrecordList = new ArrayList<>();
        checkrecordList.add(map);
        return new Result(true,"查询报告成功",checkrecordList);
    }
}
